package com.suning.sawp.web.controller;

import java.security.Principal;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.suning.sawp.dto.common.ReturnMsg;
import com.suning.sawp.dto.price.ComparePriceResult;
import com.suning.sawp.dto.price.SiteHistoryPrice;
import com.suning.sawp.intf.biz.CasComparePriceService;
import com.suning.sawp.po.StoreManSubProduct;
import com.suning.sawp.web.exception.MyGsonView;

/**
 * 
 * 比价业务控制类<br> 
 * 〈功能详细描述〉
 *
 * @author 12061818
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Controller
@RequestMapping("/bijia")
public class ComparePriceController extends DjBaseController {
    
    private static final Logger LOGGER = LoggerFactory.getLogger(ComparePriceController.class);
    
    @Resource
    CasComparePriceService casComparePriceService;
    
    /**
     * 
     * 功能描述: 关注商品<br>
     * 〈功能详细描述〉
     *
     * @param productId
     * @param productName
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/subProduct")
    public MyGsonView subProduct(String productId, String productName, Principal principal) {
        Object[] args = {productId, productName, principal.getName()};
        LOGGER.debug("ComparePriceController.subProduct, productId:{}, productName:{}, staffId:{}", args);
        ReturnMsg<String> retMsg = 
                casComparePriceService.subscribleProduct(principal.getName(), productId, productName);
        return setGsonView(retMsg);
    }
    
    /***
     * 
     * 功能描述: 取消对商品的关注<br>
     * 〈功能详细描述〉
     *
     * @param productId
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/unSubProduct")
    public MyGsonView unSubProduct(String productId, Principal principal) {
        LOGGER.debug("ComparePriceController.unSubProduct, productId:{}, staffId:{}", productId, principal.getName());
        ReturnMsg<String> retMsg = 
                casComparePriceService.unSubscribleProduct(principal.getName(), productId);
        return setGsonView(retMsg);
    }
    
    /**
     * 
     * 功能描述: 我关注的商品列表<br>
     * 〈功能详细描述〉
     *
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/mySubProducts")
    public MyGsonView mySubProducts(Principal principal) {
        LOGGER.debug("ComparePriceController.mySubProducts, staffId:{}", principal.getName());
        ReturnMsg<List<StoreManSubProduct>> retMsg =
                casComparePriceService.getMySubscribleProducts(principal.getName());
        return setGsonView(retMsg);
    }
    
    /**
     * 
     * 功能描述: 当前所有站点实时价格<br>
     * 〈功能详细描述〉
     *
     * @param productId
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/currentSitePrices")
    public MyGsonView currentSitePrices(String productId, Principal principal) {
        LOGGER.debug("ComparePriceController.currentSitePrices, productId:{}, staffId:{}", productId, principal.getName());
        ReturnMsg<ComparePriceResult> retMsg = 
                casComparePriceService.getProductSitePrices(principal.getName(), productId);
        return setGsonView(retMsg);
    }
    
    /**
     * 
     * 功能描述: 获取商品的历史价格日历<br>
     * 〈功能详细描述〉
     *
     * @param productId
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/getHistoryPrices")
    public MyGsonView getHistoryPrices(String productId) {
        LOGGER.debug("ComparePriceController.getHistoryPrices, productId:{}", productId);
        ReturnMsg<List<SiteHistoryPrice>> retMsg =
                casComparePriceService.getProductSiteHistoryPrices(productId);
        return setGsonView(retMsg);
    }
}
